package com.shuaitao.newsystem.handler;

import com.alibaba.fastjson.JSONObject;
import com.shuaitao.newsystem.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import java.util.List;
import java.util.Map;

@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
@RestControllerAdvice
public class GlobalExceptionAdvice{

  @ExceptionHandler(ConstraintViolationException.class)
  @ResponseBody
  public R handleBeanValidation(HttpServletResponse res, ConstraintViolationException e) throws Exception{
    res.setStatus(200);
    return R.error(103,"字段不能为空");
  }
}
